home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
asmutil
/
x2b11.zip
/
X2B11.ASM
< prev
Wrap
Assembly Source File
|
1989-10-14
|
18KB
|
568 lines
Comment ~
X2B.ASM
A replacement for the Exe2Bin program, which is NOT included with
PC-DOS 3.3.
written by Henry T. Nettles, Dec. 21, 1987 -- Feb. 20, 1988
compiled with MicroSoft Macro Assembler, version 5.0
The inspiration (and model) for this program was EXE2COM.C, written
by Chris Dunford.
The include module, DOS.INC, comes with MASM 5.0
The subroutine BinToStr is borrowed from the SHOW.ASM program which
also comes with MASM 5.0
Some of this code (the command line parser) is borrowed from a program
by Vernon Buerg (TABS.ASM)
This program is hereby released to the public domain.
Usage: >X2B [d:][\path\]PROG[.EXE] [d:][\path\][PROG][.COM]
The only necessary parameter is the file name of the input file. A
drive and/or path may be given if needed.
If no extension is given, .EXE is assumed. If no ouput file is
given, then the same file name with an extension of .COM is used.
WARNING: If a drive and/or path is given for the input file, and
no ouput file is given, then the input drive and/or path will be
used for the ouput (not the default directory).
This program works on my computer, on the files I have tried it on.
However, extensive testing has not been performed, and I assume no
responsibility whatever for the program. I would be interested in
bug reports, and if anyone improves the code it would be nice to
receive a copy. I can be reached at:
22547 Braken Carter
Katy, Texas 77449-3619
Toad Hall Tweak, 15 Oct 89
- Converted to .COM format
- General tightening
- Moved EXE header buffer, filename buffers to dynamic space at code end
(to reduce program size)
- Changed BinToStr procedure so it carries parms directly in AX/DI
instead of the slow pushes.
- Removed some unnecessary local variables
Comment ends ~
RECSIZE equ 512
CMDTAIL equ 80h
CR equ 0dh
LF equ 0ah
EOM equ '$'
SIZE_OF_HEADER equ 28
exe_header STRUC ; what an exe header looks like
exe_sig1 db 0 ; EXE file signature: "MZ"
exe_sig2 db 0
excess dw 0 ; image size mod 512 (valid bytes in last page)
pages dw 0 ; # of 512 byte pages in image
relo_ct dw 0 ; count of relocation table entries
hdr_size dw 0 ; size of header in paragraphs
min_mem dw 0 ; min required memory
max_mem dw 0 ; max required memory
xss dw 0 ; stack seg offset in load module
xsp dw 0 ; initial value of sp
cksum dw 0 ; file checksum
xip dw 0 ; initial value of IP
xcs dw 0 ; cs offset in load module
relo_start dw 0 ; offset of first relocatable item
ovl_num dw 0 ; overlay number
exe_header ENDS ; end of structure
CSEG SEGMENT PARA PUBLIC 'CODE'
ASSUME CS:CSEG, DS:CSEG, ES:CSEG
org 100H
X2B proc near
jmp Start ;skip over runtime data v1.1
errflag db 0 ;error flag v1.1
save_ip dw 0
handle1 dw 0
handle2 dw 0
msg1 db 'Input File ==>',eom
msg2 db ' Output File ==>',eom
msg3 db CR,LF,EOM
author db 'X2B 1.1 Public Domain Software by Henry T. Nettles'
db CR,LF,EOM
code_size_msg db 'Code Size = '
code_size_str db ' ',eom
code_start_msg db ' Code Start = '
code_start_str db ' ',eom
ip_msg db ' Initial IP = '
ip_str db ' ',CR,LF,EOM
actual_code_size_msg db 'Size of .Com file = '
actual_code_size_str db ' ',CR,LF,EOM
code_size dw 0 ; amount of code to move to .com file
code_start dw 0
no_file_msg1 db 'USAGE: >X2B [d:][\path\]file[.exe] [d:][\path\][file][.com]'
db CR,LF,EOM
open_fail_msg db 'ERROR: Open of input file failed!',CR,LF,EOM
create_fail_msg db 'ERROR: Create of output file failed!',CR,LF,EOM
disk_full_msg db 'ERROR: The disk is full!',CR,LF,EOM
Bad_Read_msg db 'I/O Error on Read!',CR,LF,EOM
bad_write_msg db 'I/O Error on Write!',CR,LF,EOM
seek_error_msg db 'I/O Error on Seek!',CR,LF,EOM
badsig_msg db 'Invalid EXE File Signature',CR,LF,EOM
hasrelo_msg db 'EXE has relocatable items',CR,LF,EOM
has_ss_msg db 'EXE has stack segment',CR,LF,EOM
bad_ip_msg db 'IP not 0 or 100h',CR,LF,EOM
too_big_msg db 'Exe file is too big to convert to COM file',CR,LF,EOM
mul_err_msg db 'Overflow on multiply',CR,LF,EOM
Start: ;v1.1
;****************************************************************************
;* Get two file names from command line
;* This portion of code was borrowed from TABS.ASM by Vernon Buerg
;****************************************************************************
xor al,al ;handy 0 v1.1
mov FNAME1,al ;insure both dynamic filename v1.1
mov FNAME2,al ; buffers are 0 v1.1
mov si,CMDTAIL ; DS:SI points to command line
sub bp,bp ;Indicates first or second name
sub ch,ch ;The PSP may contain one or two
or cl,[si] ; filenames separated by blanks v1.1
jz GetF5 ; First byte of cmdline should not be 0
mov di,offset FNAME1 ;ES:DI points to fname1 v1.1
Inc si ; point to next char from command line
; (assume that 1st char is a blank)
GetF1: Lodsb ;Copy command line to file names
; AL will contain character pointed
; to by DS:SI
cmp AL,' ' ; skip leading blanks
jne GetF2 ; not a blank -- jump
or bp,bp ; or until the length is zero
jz GetF4 ;If a second blank is found,
mov ax,2400h ; append zero and dollar sign
stosw ; mov AX to ES:DI
mov di,offset FNAME2 ;ES:DI now points to 2d filename v1.1
jmp short GetF4
GetF2: cmp AL,Cr ;Is it CR, end of line?
je GetF5 ; yes, end of command
stosb ; no, save in name
mov bp,di ; and indicate data copied
GetF4: loop GetF1
GetF5: mov ax,2400h ;Append zero and dollar sign
stosw
mov dx,offset author ;tell them who we are v1.1
mov ah,9 ;display string
int 21H
;***************************************************************************
;* DISPLAY THE TWO FILE NAMES FROM COMMAND LINE
;***************************************************************************
mov si,offset FNAME1 ;point to fname1 v1.1
xor al,al ;handy 0 v1.1
cmp al,[si] ;did user enter at least 1 file name? v1.1
jnz L1 ; is ok, we have a file name
jmp No_File1
L1:
mov di,si ;offset fname1 ; check fname1 for extension v1.1
mov cx,-1
cld ; direction of search = forward
repnz scasb ; search through file name for '\0'
not cx ; CX = length including '\0'
mov dx,cx ;save length in DX a sec v1.1
mov di,si ;offset fname1 ;point back to fname1 start v1.1
mov al,'.'
repnz scasb ; search for period in file name
jz L1a ; found the period, must have ext
mov ax,si ;offset fname1 ; no period, must add .EXE for user v1.1
add ax,dx ;fname1_len ; v1.1
dec ax ;
mov di,ax ; di points to '\0' at end of file name
mov ax,'E.' ;452eh ; ".E" backwards v1.1
stosw
mov ax,'EX' ;4558h ; "XE" backwards v1.1
stosw
mov ax,2400h ; append zero and dollar sign
stosw
L1a:
mov cx,-1 ;common code v1.1
cmp byte ptr FNAME2,0 ;did user enter 2d file name? v1.1
; (should not be 0) v1.1
jnz L2 ; fname2 is non-blank, go check for ext
mov si,offset FNAME1 ;source is FNAME1 v1.1
mov di,si ;offset FNAME1 ;into DI for a scasb v1.1
mov al,'.'
cld
repnz scasb ; search fname1 for '.'
not cx ; cx has length of fname1 including '.'
dec cx ; don't copy the period
mov di,offset FNAME2 ; let Dest. Index point to fname2 v1.1
;SI (source) is already FNAME1 v1.1
cld ; direction of movement = forward
rep movsb ; move chars from [SI] to [DI]
; CX has count (# chars to move)
jmp short L2a ; go add the ".COM"
;
L2: mov di,offset fname2 ; check fname2 for extension
xor al,al ; zero al
cld ; direction of search = forward
repnz scasb ; search through file name for '\0'
not cx ; CX = length including '\0'
mov dx,cx ; save the length in DX a sec v1.1
mov di,offset FNAME2 ;v1.1
mov al,'.'
repnz scasb ; search for period in file name
jz L2b ; found the period, must have ext
mov ax,offset FNAME2 ;v1.1
add ax,dx ;fname2_len ;add in FNAME2's length v1.1
dec ax ;adjust
mov di,ax ; di points to '\0' at end of file name
L2a: mov ax,'C.' ;432eh ; ".C" backwards v1.1